package gamegame;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class EngineStarter extends JFrame{
	JSlider one, two, three, four, five, six;
	JLabel lone, ltwo, lthree, lfour, lfive, success;
	JButton button, button2, button3, button4, button5, button6;
	boolean fansOn, ductOpen,flooded, overloaded, sandGone, shutdownFull;
	
	public EngineStarter(){
		super("Start the engines!");
		shutdownFull=false;
		overloaded=false;
		fansOn=false;
		ductOpen=false;
		flooded=false;
		sandGone=false;
		setLayout(new GridBagLayout());
		GridBagConstraints c=new GridBagConstraints();
		lone=new JLabel("Heat Distribution");
		c.gridx=0;
		c.gridy=0;
		c.insets=new Insets(10,10,10,10);
		add(lone, c);
		ltwo=new JLabel ("Com onent D nsit ");
		c.gridx=1;
		c.gridy=0;
		c.insets=new Insets(10,10,10,10);
		add(ltwo,c);
		lthree=new JLabel ("Core Damp ng");
		c.gridx=2;
		c.gridy=0;
		c.insets=new Insets(10,10,10,10);
		add(lthree,c);
		lfour=new JLabel ("Shut ow ");
		c.gridx=3;
		c.gridy=0;
		c.insets=new Insets(10,10,10,10);
		add(lfour,c);
		lfive=new JLabel ("U kno n");
		c.gridx=4;
		c.gridy=0;
		c.insets=new Insets(10,10,10,10);
		add(lfive,c);
		two=new JSlider (JSlider.VERTICAL,-50, 0, 0);
		two.setMajorTickSpacing(5);
		two.setMinorTickSpacing(1);
		two.setPaintTicks(true);
		two.setSnapToTicks(true);
		two.setPaintLabels(true);
		c.gridx=0;
		c.gridy=1;
		add(two,c);
		three=new JSlider (JSlider.VERTICAL,0, 100, 0);
		three.setMajorTickSpacing(10);
		three.setMinorTickSpacing(2);
		three.setPaintTicks(true);
		three.setPaintLabels(true);
		three.setPaintTrack(false);
		c.insets=new Insets(20,20,20,20);
		c.gridx=1;
		c.gridy=1;
		add(three,c);
		one=new JSlider(-10,30,0);
		one.setMajorTickSpacing(5);
		one.setMinorTickSpacing(1);
		one.setPaintTicks(true);
		one.setPaintLabels(true);
		c.gridx=2;
		c.gridy=1;
		one.addChangeListener(new ChangeListener(){
			@Override
			public void stateChanged(ChangeEvent arg0) {
				if(one.getValue()==one.getMaximum()){
					button2.setEnabled(true);
					if(!overloaded){
						button3.setEnabled(true);
					}
				}
				else{
					button2.setEnabled(false);
					button3.setEnabled(false);
				}
			}
		});
		add(one,c);
		four=new JSlider(0,20, 0);
		four.setMajorTickSpacing(20);
		four.setMinorTickSpacing(4);
		four.setPaintTicks(true);
		four.setSnapToTicks(true);
		four.setPaintLabels(true);
		c.gridx=3;
		c.gridy=1;
		four.addChangeListener(new ChangeListener(){
			@Override
			public void stateChanged(ChangeEvent arg0) {
				if(four.getValue()==four.getMaximum()){
					shutdownFull=true;
					if(sandGone&&!ductOpen){
						button.setEnabled(true);
					}
				}
				else{
					shutdownFull=false;
					button.setEnabled(false);
				}
			}
		});
		add(four,c);
		five=new JSlider(0,1,0);
		five.setMajorTickSpacing(1);
		five.setMinorTickSpacing(1);
		five.setPaintLabels(true);
		c.gridx=4;
		c.gridy=1;
		add(five,c);
		six=new JSlider(-10,10,0);
		six.setMajorTickSpacing(5);
		six.setMinorTickSpacing(1);
		six.setPaintTicks(true);
		c.gridwidth=2;
		c.gridx=2;
		c.gridy=2;
		add(six,c);
		button=new JButton("Divert Power to Core");
		button.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				one.setValue(one.getMaximum());
				two.setValue(two.getMaximum());
				three.setValue(three.getMaximum());
				four.setValue(four.getMaximum());
				five.setValue(five.getMaximum());
				six.setValue(six.getMaximum());
				one.setEnabled(false);
				two.setEnabled(false);
				three.setEnabled(false);
				four.setEnabled(false);
				five.setEnabled(false);
				six.setEnabled(false);
				button.setEnabled(false);
				button4.setEnabled(false);
				button2.setEnabled(false);
				button3.setEnabled(false);
				button5.setEnabled(false);
				success.setVisible(true);
				
			}
		});
		c.gridwidth=2;
		c.gridx=0;
		c.gridy=3;
		c.fill=GridBagConstraints.HORIZONTAL;
		add(button,c);
		button2=new JButton("Flood Non-Essential Systems");
		button2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				button3.setEnabled(false);
				button6.setEnabled(false);
				fansOn=false;
				flooded=true;
			}
		});
		c.gridwidth=2;
		c.gridx=2;
		c.gridy=3;
		c.fill=GridBagConstraints.HORIZONTAL;
		add(button2,c);
		button3=new JButton("Turn on Fans");
		button3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				fansOn=true;
			}
		});
		c.gridwidth=2;
		c.gridx=4;
		c.gridy=3;
		c.fill=GridBagConstraints.HORIZONTAL;
		add(button3,c);
		button4=new JButton("Open Duct");
		button4.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				button4.setEnabled(false);
				button5.setEnabled(true);
				button.setEnabled(false);
				ductOpen=true;
				if(fansOn||flooded){
					sandGone=true;
				}
			}
		});
		c.gridwidth=2;
		c.gridx=0;
		c.gridy=4;
		c.fill=GridBagConstraints.HORIZONTAL;
		add(button4,c);
		button5=new JButton("Close Duct");
		button5.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				button4.setEnabled(true);
				button5.setEnabled(false);
				ductOpen=false;
				if(four.getValue()==four.getMaximum()&&sandGone){
					button.setEnabled(true);
				}
			}
		});
		c.gridwidth=2;
		c.gridx=2;
		c.gridy=4;
		c.fill=GridBagConstraints.HORIZONTAL;
		add(button5,c);
		button6=new JButton("Overload Fans");
		button6.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				button3.setEnabled(false);
				button6.setEnabled(false);
				fansOn=false;
			}
		});
		c.gridwidth=2;
		c.gridx=4;
		c.gridy=4;
		c.fill=GridBagConstraints.HORIZONTAL;
		add(button6,c);
		button5.setEnabled(false);
		button.setEnabled(false);
		button2.setEnabled(false);
		button3.setEnabled(false);
		success=new JLabel("The engines turn on! Congratulations.");
		c.gridx=2;
		c.gridy=5;
		success.setVisible(false);
		add(success,c);
		
	}
}
